//package com.example.villagedevelop.generator.service.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.example.villagedevelop.generator.entity.Users;
//import com.example.villagedevelop.generator.mapper.UsersMapper;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.Collection;
//
////@Service
//public class MyUserDetailServiceImpl implements UserDetailsService {
//
//    @Autowired
//    private UsersMapper usersMapper;
//
//    @Autowired
//    PasswordEncoder passwordEncoder;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        //调用usersMapper方法，根据用户名查询数据库
//        QueryWrapper<Users> wrapper = new QueryWrapper<>();
//        wrapper.eq("username", username);
//        Users users = usersMapper.selectOne(wrapper);
//        if(users == null){  //数据库没有该用户名 认证失败
//            throw new UsernameNotFoundException("用户名或密码不存在!");
//        }else {
//                Collection<GrantedAuthority> authorities = new ArrayList<>();
//                authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
//                User user = new User(users.getUsername(),passwordEncoder.encode(users.getPassword()),authorities);
//                System.out.println("管理员信息："+user.getUsername()+"   "+passwordEncoder.encode(user.getPassword())+"  "+user.getAuthorities());
//                return user;
//        }
//    }
//}
